﻿Public Class Form3GongWei
    Public usr As String
    Dim objGt As New clsGt
    Dim objGtProcedure As New clsGtProcedure
    Dim objGtProcedureDetails As New clsGtProcedureDetails
    Dim dt As DataTable
    Private Sub Form3GongWei_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        setData()
    End Sub

    Public Sub setData()
        dt = objGt.getCurrentGt("1", "1", "1")
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dt
    End Sub

    Public Sub setDgvData()
        Dim dtProcedure As DataTable = objGtProcedure.selectGtProcedure(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
        DataGridView3.AutoGenerateColumns = False
        DataGridView3.DataSource = dtProcedure
        Dim dtOper As DataTable = objGtProcedureDetails.getGtProcedureDetailsList(dgv.SelectedRows(0).Cells("sys_id").Value.ToString(), "2")
        dgvOper.AutoGenerateColumns = False
        dgvOper.DataSource = dtOper
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            setDgvData()
        End If
    End Sub

    Private Sub btnOper_Click(sender As Object, e As EventArgs) Handles btnOper.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim formOper As New FormOper()
            formOper.usr = usr
            formOper.source = "3gw"
            formOper.b_gt_sys_id = dgv.SelectedRows(0).Cells("sys_id").Value.ToString()
            formOper.ok_num_all = dgv.SelectedRows(0).Cells("ok_num").Value.ToString()
            If DataGridView3.SelectedRows.Count > 0 Then
                formOper.oper_num_all = DataGridView3.SelectedRows(0).Cells("Col_oper_num").Value.ToString()
            Else
                formOper.oper_num_all = "0"
            End If
            formOper.current_procedure_No = 2
            formOper.ShowDialog(Me)
        End If
    End Sub

    Private Sub btnValidityOper_Click(sender As Object, e As EventArgs) Handles btnValidityOper.Click
        If dgvOper.SelectedRows.Count > 0 Then
            If dgvOper.SelectedRows(0).Cells("Colvalidity").Value.ToString().Equals("1") Then
                If MsgBox("确认要进行作废吗？", vbYesNo, "提示") = vbYes Then
                    Dim sys_id As String = dgvOper.SelectedRows(0).Cells("Colsys_id").Value.ToString()
                    Dim procedure_no As String = dgvOper.SelectedRows(0).Cells("Colprocedure_no").Value.ToString()
                    Dim b_gt_sys_id As String = dgvOper.SelectedRows(0).Cells("Colb_gt_sys_id").Value.ToString()
                    Dim oper_num As String = dgvOper.SelectedRows(0).Cells("Coloper_num").Value.ToString()
                    Dim rtn As Integer = objGtProcedureDetails.updateValidity(sys_id, oper_num, b_gt_sys_id, procedure_no, usr)
                    If rtn <> -2 Then
                        MsgBox("作废成功")
                        setDgvData()
                    Else
                        MsgBox("作废失败")
                    End If
                End If
            Else
                MsgBox("该记录已作废")
            End If
        End If
    End Sub

    Private Sub btnValidity_Click(sender As Object, e As EventArgs) Handles btnValidity.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim rtn_validity As Integer = objGt.update_validity(dgv.SelectedRows(0).Cells("sys_id").Value.ToString())
            If rtn_validity <> -2 Then
                MsgBox("作废成功"， vbYes, "提示")
                setData()
            Else
                MsgBox("作废失败", vbYes, "提示")
            End If
        End If
    End Sub
End Class